Author: User

ELEC 1601 Group Assignment - PIC Buggy
How does it all work?

The Theory
The buggy’s direction is controlled by input from two sensors, situated at the front and right of the circuit board.
For the buggy to propel itself around the maze, the main theory behind the design is to drive along the right wall, essentially ‘hugging’ it. This is achieved by turning the left wheel faster than the right one when no sensors are activated. The result is that the buggy veers strongly to the right.
Upon touching the right wall, the right sensor is activated, initiating a short turn away from the wall (left). By this method the buggy appears to ‘bounce’ off the right wall, following its turns.
The frontal sensor is used to detect when the right wall veers to the right. When this sensor is triggered, the buggy makes a 90 degree turn to the left.
The combination of these two responses in theory would be seen to be enough to allow successful navigation of the maze, however due to the size of the buggy in proportion to the width of the maze, it occasionally becomes stuck in a position which will not automatically be corrected with this initial logic.
It was for this reason that we developed the extension stage of our logic which involves detecting a jam and responding appropriately. In a situation where neither sensor is triggered over a short period of time it is assumed that the buggy must be stuck and so a short reverse and turn to the right successfully acts to free the buggy from the wall.

The Buggy

In addition, a physical modification was also made to the buggy where a pen lid is attached near the left sensor, this was done to stop the left sensor being hit when the buggy was too close to the left wall. Though a simple solution, it has been found through testing to be incredibly effective, allowing the buggy to successfully escape any jams that occur.
The combination of an exponential turning rate along with the ability of the buggy to free itself when jammed allows our buggy to successfully navigate the maze unaided for an unlimited number of repetitions.
By Aaron Cowie, Andrew Bronier, Lynden Shields, Crystal Li, Lachlan Craig, Huang Jian.

The Code
autorecover:
stuck_right_sensor_counter = 0
let pins = %00100000
pause 300
goto main
findwall:
let pins = %01010100
pause 300
findloop:
stuck_no_sensor_counter = stuck_no_sensor_counter + 1
if stuck_no_sensor_counter = 100 then reverseright
if front_sensor = 1 or right_sensor = 1 then main
let pins = %10010011
pause 23
let pins = %01010011
sound 0, (300,diminishing_pause)
let diminishing_pause = diminishing_pause - 3
if diminishing_pause < 3 then resetdiminishingpause
goto findloop
resetdiminishingpause:
diminishing_pause = 4
goto findloop
left:
if not_first_touch = 1 then goto next1
not_first_touch = 1
goto next2
next1:
if front_sensor_touch_proximity < 20 then adddead_end_counter
next2:
if dead_end_counter = 2 then goto dance
front_sensor_touch_proximity = 0
let pins = %00000111
sound 0, (350,20)
let pins = %00000011
sound 0, (340,20)
let pins = %00000100
sound 0, (330,20)
let pins =%01100100
pause 1300
goto main
adddead_end_counter:
dead_end_counter=dead_end_counter + 1
not_first_touch = 0
goto next2
reverseright:
stuck_no_sensor_counter = 0

let pins = %10000011
sound 0, (127,50)
goto findwall
dance:
if already_danced = 1 then goto main
let pins = %01100100
sound 0, (96,15)
pause 40
sound 0, (96,15)
pause 100
sound 0, (96,20)
pause 100
sound 0, (87,15)
pause 40
sound 0, (96,25)
pause 100
sound 0, (101,25)
pause 300
sound 0, (87,25)
pause 400
sound 0, (87,25)
pause 150
sound 0, (82,25)
pause 220
sound 0, (76,30)
pause 220
SOUND 0, (87,25)
pause 140
sound 0, (96,25)
pause 140
sound 0, (87,15)
pause 40
sound 0, (86,25)
pause 220
sound 0, (94,15)
pause 220
sound 0, (97,15)
pause 220
sound 0, (99,15)
already_danced = 1 goto main
goto main